<?php
namespace App\Api\Models;

use App\Api\Bases\BaseController;
use App\Api\Services\JsonService;
use Illuminate\Database\Eloquent\Model;

class CmcOutMoney extends Model
{
    protected $table = 'cmc_out_money';
    /*
     * 退款订单
     */
    public static  function  outMoney($order_sn)
    {
         $dateTime=(new BaseController())->NowTime();
        //'订单类型[拼团0砍价1秒杀2]'
        switch($order_sn['type'])
        {
            case 0:
                //查询入库
                self::typeOutMoney($order_sn);
               self::insert(['type'=>$order_sn['type'],'uid'=>$order_sn['uid'],'pintuan_id'=>$order_sn['pintuan_id'],'total_money'=>$order_sn['total_money'],'out_time'=>$dateTime,'pay_type'=>$order_sn['pay_type'],'order_sn'=>$order_sn['order_sn']]);
                break;
            case 1:
                self::insert(['type'=>$order_sn['type'],'uid'=>$order_sn['uid'],'seckill_id'=>$order_sn['seckill_id'],'total_money'=>$order_sn['total_money'],'out_time'=>$dateTime,'pay_type'=>$order_sn['pay_type'],'order_sn'=>$order_sn['order_sn']]);
                break;
            case 2:
                self::insert(['type'=>$order_sn['type'],'uid'=>$order_sn['uid'],'bargain_id'=>$order_sn['bargain_id'],'total_money'=>$order_sn['total_money'],'out_time'=>$dateTime,'pay_type'=>$order_sn['pay_type'],'order_sn'=>$order_sn['order_sn']]);
                break;
            default:
                return JsonService::fail('传值错误','',config('code.HTTP_FAIL'));
        }
    }
    /*
     * 判断支付方式
     */
    public static  function typeOutMoney($order_sn)
    {
        $pay_type=$order_sn['pay_type'];
        switch($pay_type)
        {
            case 0:
                //查询入库
                //改库
        $total_money=CmcMembers::where(['member_id'=>$order_sn['uid']])->first(['balance']);
        CmcMembers::where(['member_id'=>$order_sn['uid']])->update(['balance'=>$order_sn['total_money']+$total_money['balance']]);
                break;
            case 1:
                break;
            case 2:
                break;
            case 3:
                break;
                default:
                return JsonService::fail('传值错误','',config('code.HTTP_FAIL'));
        }
    }


}